package com.example.streams;

import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.example.beanutils.User;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class StreamTest2 {
    public static void main(String[] args) {
        /**
         * 统计同名用户的出现次数
         */
        User user1 = new User("王五", 1, "男");
        User user2 = new User("王五", 99, "男");
        User user3 = new User("王五", 2, "男");
        User user4 = new User("张三", 2, "男");
        User user5 = new User("", 2, "男");
        User user6 = new User(null, 2, "男");
        List<User> list = new ArrayList<>();
        list.add(user1);
        list.add(user2);
        list.add(user3);
        list.add(user4);
        list.add(user5);
        list.add(user6);
        //  Function.identity() 同等于 a -> a
        //转为ma，姓名为key，同名取年纪大的
        List<String> ss = list.stream()
                .filter(e -> ObjectUtils.isNotNull(e.getName()))
                .map(User::getName)
                .collect(Collectors.toList());
        System.out.println(ss);
    }
}
